<template>
  <div id="app">
    <div class="left">
      <!-- <img src="../public/loginImg.png" alt="" /> -->
    </div>
    <div class="content">
      <div class="title">欢迎登录</div>
      <div class="formData">
        <el-form ref="form" :model="form">
          <el-form-item>
            <el-input v-model="form.name" prefix-icon="el-icon-user" placeholder="请输入用户名"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="form.password" prefix-icon="el-icon-lock" type="password" show-password placeholder="请输入密码"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="login">登 录</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      form: {
        name: "",
        password: ""
      }
    };
  },
  methods: {
    async login() {
      const result = await window.electronAPI.login(this.form.name, this.form.password);
      if (result.success) {
        this.$message({
          message: '登陆成功',
          type: 'success',
          duration: 1000,
          onClose: () => {
            this.$router.push("/detail");
          }
        });
      } else {
        this.$message.error('用户名或密码错误');
      }
      
    }
  },
  mounted() {}
};
</script>

<style scoped>
html{
  margin: 0;
  padding: 0;
}

body {
  margin: 0;
  padding: 0;
}

#app {
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: row;
}

.left {
  width: 50%;
  height: auto;
  background-image: url("../public/loginImg.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.content {
  width: 50%;
  height: auto;
  background-color: #fff;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.title {
  margin: 100px 0 30px;
  font-size: 28px;
  font-weight: bold;
}

.formData {
  display: flex;
  flex-direction: column;
  width: 60%;
}

.el-form-item:last-child {
  text-align: center;
}

button {
  margin-top: 20px;
  width: 100%;
  font-size: 16px;
}


</style>